package com.dhcc.logs.controller;

import java.util.List;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.dhcc.logs.common.annotation.Log;
import com.dhcc.logs.common.base.BaseApiController;
import com.dhcc.logs.common.enums.BusinessType;
import com.dhcc.logs.common.response.Result;
import com.dhcc.logs.common.response.ResultCode;
import com.dhcc.logs.entity.User;
import com.dhcc.logs.entity.vo.UserVo;
import com.dhcc.logs.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@Api(tags = "modelMapper接口")
@RequestMapping("/index")
public class IndexController extends BaseApiController {
	private static final Logger log = LoggerFactory.getLogger(IndexController.class);

	@Autowired
	UserService userService;
	
    @ApiOperation(value = "查询用户")
//    @Log(title = "查询用户", businessType = BusinessType.FIND)
    @RequestMapping(value = "/query",method = RequestMethod.GET)
    public Result query(){
        log.info("查询用户：");
        List<User> usesList = userService.findAll();
        //采用Jdk1.8stream方式
        List<UserVo> userVos = usesList.stream().map(d ->{
        	//采用modelMapper转换对象
        	return modelMapper.map(d, UserVo.class);
        }).collect(Collectors.toList());
        return new Result(ResultCode.SUCCESS,userVos);
    }
}